
var sjyjqkChart;
var returnSjyjqkData = [];

var sjyjqkObj = new Vue({
	el: '#sjyjqkTab',
	data: {
		year: '',
		isAll: false,
		zsList:{
			jj: true,
			sjxd: false,
			sjsj: false,
			jzrs: false
		},
		tbList: {
			jjtb: true,
			sjxdtb: false,
			sjsjtb: false,
			jzrstb: false
		},
		hbList: {
			jjhb: true,
			sjxdhb: false,
			sjsjhb: false,
			jzrshb: false
		}
	},
	created: function(){


	},
	watch:{
		"zsList.jj":function(val, oldVal){	//接警
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"zsList.sjxd":function(val, oldVal){	//搜救行动
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"zsList.sjsj":function(val, oldVal){	//搜救时间
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"zsList.jzrs":function(val, oldVal){	//救助人员
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"tbList.jjtb":function(val, oldVal){	//接警同比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"tbList.sjxdtb":function(val, oldVal){	//搜救行动同比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"tbList.sjsjtb":function(val, oldVal){	//搜救时间同比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"tbList.jzrstb":function(val, oldVal){	//救助人员同比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		}
		/*
		,
		"hbList.jjhb":function(val, oldVal){	//接警环比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"hbList.sjxdhb":function(val, oldVal){	//搜救行动环比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"hbList.sjsjhb":function(val, oldVal){	//搜救时间环比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		"hbList.jzrshb":function(val, oldVal){	//救助人员环比
    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true);
		},
		*/
	},
	methods:{
		checkAll: function(){
			this.zsList.jj = this.isAll;
			this.zsList.sjxd　= this.isAll;
			this.zsList.sjsj　= this.isAll;
			this.zsList.jzrs　= this.isAll;
			
			this.tbList.jjtb　= this.isAll;
			this.tbList.sjxdtb　= this.isAll;
			this.tbList.sjsjtb　= this.isAll;
			this.tbList.jzrstb　= this.isAll;
			
			/*
			this.hbList.jjhb　= this.isAll;
			this.hbList.sjxdhb　= this.isAll;
			this.hbList.sjsjhb　= this.isAll;
			this.hbList.jzrshb　= this.isAll;
			*/

    		sjyjqkChart.setOption(subStrOptionSjyjqk(returnSjyjqkData),true)
		}
	}
})
function searchOrTimesjyj(){
	if($('#timesjyj').val()==""){
		sjyjqkObj.year =new Date().getFullYear();
	}
	else{
		sjyjqkObj.year =$('#timesjyj').val();}
	$.ajax({ 
		type: "POST",
		url: "/tszt/findsjfb.jspx", 
		data: {channelIds: 369, year: sjyjqkObj.year, orderBy: 36},
		success: function(data){
			if(data.code == 200){
				if(data.body.length == 0){
					sjyjqkObj.year = new Date().getFullYear() - 1;
					bindSjyjqkData();
				}
				returnSjyjqkData = data.body;
			}

			bindSjyjqk(returnSjyjqkData);
      	}
	});
}


function bindSjyjqkData(){
	if(returnSjyjqkData.length == 0){
		
		$.ajax({ 
			type: "POST",
			url: "/tszt/findsjfb.jspx", 
			data: {channelIds: 369, year: sjyjqkObj.year, orderBy: 36},
			success: function(data){
				if(data.code == 200){
					if(data.body.length == 0){
						sjyjqkObj.year = new Date().getFullYear() - 1;
						bindSjyjqkData();
					}
					returnSjyjqkData = data.body;
				}
	
				bindSjyjqk(returnSjyjqkData);
	      	}
		});
	}
}

function subStrLegendSjyjqk(){
	var legend = [];

	if(sjyjqkObj.zsList.jj)
		legend.push('接警');
    if(sjyjqkObj.zsList.sjxd)
		legend.push('搜救行动');
    if(sjyjqkObj.zsList.sjsj)
		legend.push('搜救时间');
    if(sjyjqkObj.zsList.jzrs)
		legend.push('救助人员');
	return legend;
}

function subStrXAxisSjyjqk(returnSjyjqkData){
	var xAxis = [];
	if(returnSjyjqkData.length<12){
		xAxis=['1月份','2月份','3月份','4月份','5月份','6月份','7月份','8月份','9月份','10月份','11月份','12月份'];
	}
	else{
	returnSjyjqkData.forEach(function(month){ 
		xAxis.push(month.attr_month + '月份');
	}); 
	}
	return xAxis;
}


function subStrSeriesSjyjqk(returnSjyjqkData){
	var series = [];

	var jjData = [];
	var jjDataTb = [];
	var jjDataHb = [];

	var sjxdData = [];
	var sjxdDataTb = [];
	var sjxdDataHb = [];

	var sjsjData = [];
	var sjsjDataTb = [];
	var sjsjDataHb = [];

	var jzrsData = [];
	var jzrsDataTb = [];
	var jzrsDataHb = [];


	returnSjyjqkData.forEach(function(val){ 
		//接警
		jjData.push(val.attr_jj); //总数
		jjDataTb.push(val.attr_jjtb);	//同比
		//jjDataHb.push(val.attr_jjhb);//环比
		//搜救行动
		sjxdData.push(val.attr_sjxd); //总数
		sjxdDataTb.push(val.attr_sjxdtb);	//同比
		//sjxdDataHb.push(val.attr_sjxdhb);//环比
		//搜救时间
		sjsjData.push(val.attr_sjsj); //总数
		sjsjDataTb.push(val.attr_sjsjtb);	//同比
		//sjsjDataHb.push(val.attr_sjsjhb);//环比
		//救助人员
		jzrsData.push(val.attr_jzrs); //总数
		jzrsDataTb.push(val.attr_jzrstb);	//同比
		//jzrsDataHb.push(val.attr_jzrshb);//环比
	}); 
	

	if(sjyjqkObj.zsList.jj){	//接警
	    var d = 
		{
            name: '接警',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5bc0de",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: jjData
        };
	    series.push(d);
	}

	if(sjyjqkObj.tbList.jjtb){	//接警同比
		var d = 
      	{
             name: '接警同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
					 color: "#FF3300",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: jjDataTb
        };

	    series.push(d);
	}


	if(sjyjqkObj.hbList.jjhb){	//接警环比
		var d = 
      	{
             name: '接警环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#003300",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: jjDataHb
        };

	    series.push(d);
	}


	if(sjyjqkObj.zsList.sjxd){	//搜救行动
	    var d = 
		{
            name: '搜救行动',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5cb85c",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: sjxdData
        };
	    series.push(d);
	}

	if(sjyjqkObj.tbList.sjxdtb){	//搜救行动同比
		var d = 
      	{
             name: '搜救行动同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#5cb85c",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: sjxdDataTb
        };

	    series.push(d);
	}


	if(sjyjqkObj.hbList.sjxdhb){	//搜救行动环比
		var d = 
      	{
             name: '搜救行动环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#5cb85c",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: sjxdDataHb
        };

	    series.push(d);
	}

	if(sjyjqkObj.zsList.sjsj){	//搜救时间
	    var d = 
		{
            name: '搜救时间',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#0078c1",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: sjsjData
        };
	    series.push(d);
	}

	if(sjyjqkObj.tbList.sjsjtb){	//搜救时间同比
		var d = 
      	{
             name: '搜救时间同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#0078c1",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: sjsjDataTb
        };

	    series.push(d);
	}


	if(sjyjqkObj.hbList.sjsjhb){	//搜救时间环比
		var d = 
      	{
             name: '搜救时间环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#0078c1",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: sjsjDataHb
        };

	    series.push(d);
	}

	if(sjyjqkObj.zsList.jzrs){	//救助人员
	    var d = 
		{
            name: '救助人员',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#f0ad4e",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: jzrsData
        };
	    series.push(d);
	}

	if(sjyjqkObj.tbList.jzrstb){	//救助人员同比
		var d = 
      	{
             name: '救助人员同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#f0ad4e",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: jzrsDataTb
        };

	    series.push(d);
	}


	if(sjyjqkObj.hbList.jzrshb){	//救助人员环比
		var d = 
      	{
             name: '救助人员环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#f0ad4e",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: jzrsDataHb
        };

	    series.push(d);
	}

	return series;
}

function subStrOptionSjyjqk(){

	var legendData = subStrLegendSjyjqk();
	var xAxisData = subStrXAxisSjyjqk(returnSjyjqkData);
	var seriesData = subStrSeriesSjyjqk(returnSjyjqkData);

    var option = {
    		toolbox: {
  			　　show: true,
  			   right: 20,     			  
  			　　feature: {
  			　　　　saveAsImage: {
  			　　　　show:true,
  			　　　　excludeComponents :['toolbox'],
  			　　　　pixelRatio: 2,
  			  itemStyle: {
  	                color: '#254065'
  	            }
  			　　　　}
  			　　}
  			},
    		title: {
    			text: sjyjqkObj.year + '年'
    		},	
    		
    		 tooltip: {
             	trigger: 'axis',
             	 axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                     type: 'line'        //指示器类型。
                 },
                 formatter: function (params) {//提示框自定义
                     return formatterTip(params);
                 },
                
    		 },
               

            legend: {
                data: legendData,
                textStyle: {
                    color: '#A7A7A7',
                },
            },
          
            xAxis: {
                data: xAxisData
            },

            yAxis: [
            	{
                    type: 'value',
                    name: '总数'
                },
                {
                    type: 'value',
                    axisLabel: {
                        show: true,
                        interval: 'auto',
                        formatter: '{value}%'
                    },
                    name: '百分比%'
                }
            ],
        
           series: seriesData
		};
    
    
    return option;
}

function bindSjyjqk(returnSjyjqkData){

	sjyjqkChart = echarts.init(document.getElementById('chartSjyjqk'));

    var option = subStrOptionSjyjqk(returnSjyjqkData);
	
    // 使用刚指定的配置项和数据显示图表。
    sjyjqkChart.setOption(option);
}